//
//  Manage2OfCell.m
//  MY Project For Sport
//
//  Created by dllo on 16/2/25.
//  Copyright © 2016年 dilo. All rights reserved.
//

#import "Manage2OfCell.h"
#import "ModelForManage2.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "DataBaseHandle.h"
#import <DKNightVersion.h>

#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

#define WEIGHTT [UIScreen mainScreen].bounds.size.width / 375
#define HEIGHTT [UIScreen mainScreen].bounds.size.height / 667



@interface Manage2OfCell ()

@property (nonatomic, retain)UIImageView *teamImage;

@property (nonatomic, retain)ModelForManage2 *model;


@end

@implementation Manage2OfCell

- (void)dealloc {
    [_teamImage release];
    [_labelForTitle release];
    [_button release];
    [_model release];
    
    [super dealloc];
    
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        self.contentView.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
        [self createSubView];
        
    }
    
    
    return self;
    
    
}

- (void)createSubView {
    
    
    self.teamImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.teamImage];
    [_teamImage release];
    
    
    self.labelForTitle = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelForTitle];
    [_labelForTitle release];
    
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.button];
    
    
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.teamImage.frame = CGRectMake(10 * WEIGHTT, 10 * HEIGHTT, WIDTH / 8, HEIGHT - 20 * HEIGHTT);
    //  self.teamImage.backgroundColor = [UIColor orangeColor];
    
    
    self.labelForTitle.frame = CGRectMake(20 * WEIGHTT + WIDTH / 8 , 10 * HEIGHTT, WIDTH / 4, HEIGHT - 20 * HEIGHTT);
    self.labelForTitle.dk_textColorPicker = DKColorWithColors([UIColor blackColor], [UIColor whiteColor]);
    // self.labelForTitle.backgroundColor = [UIColor redColor];
    
    self.button.frame = CGRectMake(WIDTH - 60 * WEIGHTT, 10 * HEIGHTT, 40 * WEIGHTT, HEIGHT - 20 * HEIGHTT);
    // self.button.backgroundColor = [UIColor yellowColor];
    
}



- (void)passModelForManage:(ModelForManage2 *)model {


    self.model = model;
    [self.teamImage sd_setImageWithURL:[NSURL URLWithString:model.logo_big]];
    self.labelForTitle.text = model.name_cn;
    
    [self.button setImage:[UIImage imageNamed:@"iconfont-guanzhu"] forState:UIControlStateNormal];
    [self.button addTarget:self action:@selector(saveAction:) forControlEvents:UIControlEventTouchUpInside];

}


- (void)saveAction:(UIButton *) button {
    
    if (self.save == NO) {
        
        [[DataBaseHandle shareDataBaseHandle] insertModel:self.model];
        [self.button setImage:[UIImage imageNamed:@"iconfont-guanzhu-2"] forState:UIControlStateNormal];
        self.save = YES;
        
    } else {
        
        [[DataBaseHandle shareDataBaseHandle] deleteWithModel:self.model];
        
        [self.button setImage:[UIImage imageNamed:@"iconfont-guanzhu"] forState:UIControlStateNormal];
        self.save = NO;
        
    }
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
